package com.iot.ammeter.service.impl.android.balance;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iot.ammeter.dto.app.balance.BalanceUserInfoDTO;
import com.iot.ammeter.entity.android.balance.Balance;
import com.iot.ammeter.mapper.android.balance.BalanceMapper;
import com.iot.ammeter.service.android.balance.BalanceService;
import com.iot.ammeter.utils.CheckTool;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * app端用户余额表 服务类
 * </p>
 *
 * @author yjx
 * @since 2021-10-24
 */
@Service
@Transactional
public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, Balance> implements BalanceService {

    private final BalanceMapper balanceMapper;

    public BalanceServiceImpl(BalanceMapper balanceMapper) {
        this.balanceMapper = balanceMapper;
    }

    /**
     * 查询用户充值信息
     *
     * @param email 邮箱号
     * @return
     */
    @Override
    public Map<String, List<BalanceUserInfoDTO>> selectBalanceInfo(String email) {
        if (!CheckTool.isEmail(email)) {
            return null;
        }
        List<BalanceUserInfoDTO> balanceUserInfoDTOS = balanceMapper.selectBalanceInfo(email);
        Map<String, List<BalanceUserInfoDTO>> map = new HashMap<>();
        map.put("userBalanceInfo", balanceUserInfoDTOS);
        return map;
    }


}
